package com.zbcz.erp.network

import com.zbcz.erp.ErpApplication
import com.zbcz.erp.bean.ApplyHistoryBean
import com.zbcz.erp.bean.BaseBean
import com.zbcz.erp.bean.BusinessAddBean
import com.zbcz.erp.bean.BusinessApplyBean
import com.zbcz.erp.bean.DictItem
import com.zbcz.erp.bean.DoneJobBean
import com.zbcz.erp.bean.LoginRequestBean
import com.zbcz.erp.bean.LoginResult
import com.zbcz.erp.bean.MyToolsBean
import com.zbcz.erp.sp.SharedPreferencesManager
import okhttp3.MultipartBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.Streaming
import retrofit2.http.Url


interface ErpApi {
    @POST("/jeecg-boot/sys/mLogin")
    suspend fun login(@Body loginRequestBean: LoginRequestBean): BaseBean<LoginResult>

    @GET("/jeecg-boot/actTask/todoList")
    suspend fun getToDoList(
        @Query("name") name: String, @Query("token") token: String
    ): BaseBean<List<DoneJobBean>>

    @GET("/jeecg-boot/actTask/doneList")
    suspend fun getDoneList(
        @Query("name") name: String = "",
        @Query("pageNumber") pageNumber: String = "1",
        @Query("pageSize") pageSize: String = "50",
        @Query("order") order: String = "des",
        @Query("token") token: String
    ): BaseBean<List<DoneJobBean>>

    @GET("/jeecg-boot/actBusiness/listData")
    suspend fun getDoingBusinessList(
        @Query("name") name: String = "",
        @Query("pageNumber") pageNumber: String = "1",
        @Query("pageSize") pageSize: String = "50",
        @Query("order") order: String = "des",
        @Query("token") token: String
    ): BaseBean<List<DoneJobBean>>


    @GET("jeecg-boot/activiti_process/listData")
    suspend fun getToolsCollections(@Query("status") status: String = "1"): BaseBean<List<MyToolsBean>>

    @POST("/jeecg-boot/actBusiness/add")
    suspend fun businessAdd(
        @Body addBean: BusinessAddBean
    ): BaseBean<String>

    @POST("/jeecg-boot/actBusiness/apply")
    suspend fun businessApply(
        @Body applyBean: BusinessApplyBean
    ): BaseBean<String>

    /**
     * 赞同.
     */
    @GET("/jeecg-boot/actTask/pass")
    suspend fun actTaskPass(
        @Query("id") id: String,
        @Query("procInstId") procInstId: String,
        @Query("comment") comment: String = "",
        @Query("file") file: String = "",
    ): BaseBean<String>

    /**
     * 驳回
     */
    @GET("/jeecg-boot/actTask/pass")
    suspend fun actTaskBack(
        @Query("id") id: String,
        @Query("procInstId") procInstId: String,
        @Query("comment") comment: String = "",
        @Query("file") file: String = "",
    ): BaseBean<String>

    @POST("/jeecg-boot/sys/common/upload")
    @Multipart
    suspend fun uploadImage(@Part file: MultipartBody.Part): BaseBean<String>

    //
    //actBusiness/getForm?tableId=&tableName=
    @GET("/jeecg-boot/actBusiness/getForm")
    suspend fun actBusinessGetForm(
        @Query("tableId") tableId: String,
        @Query("tableName") tableName: String = "",
        @Query("token") token: String = SharedPreferencesManager.getToken(ErpApplication.mApplication),
    ): BaseBean<BusinessAddBean>

    @POST("/jeecg-boot/actBusiness/editForm")
    suspend fun editGetForm(
        @Body addBean: BusinessAddBean
    ): BaseBean<BusinessApplyBean>

    @GET
    @Streaming
    suspend fun downloadFile(@Url fileUrl: String?): Response<ResponseBody>

    //http://192.168.1.135:9991/jeecg-boot/actTask/historicFlow/18377


    @GET("jeecg-boot/actTask/historicFlow/{id}")
    suspend fun getHistoricFlow(
        @Path("id") id: String,
        @Query("token") token: String
    ): BaseBean<List<ApplyHistoryBean>>

    @GET("jeecg-boot/actBusiness/cancel")
    suspend fun cancel(
        @Query("id") id: String,
        @Query("procInstId") procInstId: String
    ): BaseBean<String>

    @GET("jeecg-boot/sys/api/getDictItems")
    suspend fun getDictItems(
        @Query("dictCode") dictCode: String
    ): List<DictItem>

}

